﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BookManage
{
    public partial class Login : Form
    {
        public Login()
        {
            InitializeComponent();
        }
        private void login()
        {
            //用户选中
            if (radioButtonuser.Checked == true)
            {
                Dao dao = new Dao();
                string sql = $"select * from t_user where id = '{textBoxaccount.Text}'and psw = '{textBoxpassword.Text}';";
                IDataReader dc = dao.read(sql);

                if(dc.Read())
                {
                    Data.UID = dc["id"].ToString();
                    Data.UName = dc["name"].ToString();

                    User user = new User();
                    this.Hide();
                    user.ShowDialog();
                    this.Show();
                }
                else//查询失败
                {
                    MessageBox.Show("登录失败");
                }
           
            }

            //管理员选中
            if (radioButtonadmin.Checked==true)
            {
                Dao dao = new Dao();
                string sql = $"select * from t_admin where id = '{textBoxaccount.Text}'and psw = '{textBoxpassword.Text}';";
                IDataReader dc = dao.read(sql);

                if(dc.Read())
                {
                    Admin admin = new Admin();
                    this.Hide();
                    admin.ShowDialog();
                    this.Show();
                }
                else
                {
                    MessageBox.Show("登录失败");
                }
            }
        }
        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            if(textBoxaccount.Text!=String.Empty)
            {
                login();
            }
            else if(textBoxaccount.Text==String.Empty)
            {
                MessageBox.Show("输入为空，请重新输入");
            }
        }
    }
}
